<%@ page import="java.sql.*" %><%--
  Created by IntelliJ IDEA.
  User: Mr.Zhang
  Date: 2018/3/22
  Time: 11:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%
    request.setCharacterEncoding("UTF-8");
    String  id=request.getParameter("id");   //获取表单提交的数据
    String name=request.getParameter("userName");
    String password=request.getParameter("password");

    Connection connection=null;
    PreparedStatement statement=null;
    ResultSet resultSet=null;

    String sql="insert INTO t_users VALUES (?,?,?)";

    Class.forName("com.mysql.jdbc.Driver");

    connection= DriverManager.getConnection(
            "jdbc:mysql://localhost:3306/sctu_javaweb_2018?useUnicode=true&characterEncoding=UTF-8",
            "root",
            "123456"
    );
    statement=connection.prepareStatement(sql);

    //将获取到的数据写进数据库
    statement.setString(1, id);
    statement.setString(2,name);
    statement.setString(3,password);
    int result=statement.executeUpdate();
    String msg="添加失败！";
    if (result==1){
        msg="添加成功！";
    }

    statement.close();
    connection.close();
    //resultSet=statement.executeQuery(sql);
%>
<script>window.alert('<%=msg%>');</script>
<%
    response.setHeader("Refresh","1;url=userList.jsp");
%>

